﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using NGridDrawer.Draw;
using NGridDrawer.Report;

namespace NGridDrawer.Components
{
    ///<summary>
    /// This class Provide a way to attach a comment with a cell in a <see cref="DataGridView"/> instance
    ///</summary>
    [ToolboxBitmap(typeof (PrintDocument), "PrintDocument.bmp")]
    public class DataGridViewAnnotatedDrawerComponent : GridAnnotatedDrawerComponent
    {
        private DataGridViewAbstractDrawerComponent _component;

        /// <summary>
        /// 	<para>Initializes an instance of the <see cref="DataGridViewAnnotatedDrawerComponent"/> class.</para>
        /// </summary>
        public DataGridViewAnnotatedDrawerComponent()
        {
        }

        /// <summary>
        /// 	<para>Initializes an instance of the <see cref="DataGridViewAnnotatedDrawerComponent"/> class.</para>
        /// </summary>
        /// <param name="container"></param>
        public DataGridViewAnnotatedDrawerComponent(IContainer container) : base(container)
        {
        }


        /// <summary>Get/Set Component Property</summary>
        public override IDrawerComponent Component
        {
            get { return base.Component; }
            set
            {
                if (Equals(value))
                    throw new InvalidOperationException("Choose an other component please");

                if (_component != value)
                {
                    var tmpComponent = value as DataGridViewAbstractDrawerComponent;

                    

                    if (value != null && tmpComponent ==null)
                        throw new InvalidOperationException(
                            "This Component must extends DataGridViewAbstractDrawerComponent");

                    _component = tmpComponent;

                    base.Component = _component;
                }
            }
        }

        ///<summary>
        /// Load a <see cref="DataGridViewAnnotatedDrawer"/> instance
        ///</summary>
        ///<returns>Return the loaded instance</returns>
        protected override GridAnnotatedDrawer CreateEncapsulatedDrawer()
        {
            return new DataGridViewAnnotatedDrawer(_component.Drawer);
        }
    }
}